package br.com.winesys.geta.databinding.component.table.renderers;

import java.awt.Component;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;

public class DateTableCellRenderer extends NoBorderTableCellRenderer {

  private DateFormat dateFormat;

  public DateTableCellRenderer() {
    this.dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM);
  }

  public DateTableCellRenderer(String format) {
    this.dateFormat = new SimpleDateFormat(format);
  }

  public DateTableCellRenderer(DateFormat dateFormat) {
    this.dateFormat = dateFormat;
  }

  @Override
  public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    DefaultTableCellRenderer renderer = (DefaultTableCellRenderer) super.getTableCellRendererComponent(table, this.dateFormat.format(value), isSelected, hasFocus, row, column);
    renderer.setHorizontalAlignment(SwingConstants.RIGHT);
    return renderer;
  }
}
